package com.hmy.contract.service.contract.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmy.ccp.error.exception.HMYRuntimeException;
import com.hmy.contract.dal.mapper.ContractConfigMapper;
import com.hmy.contract.dal.po.ContractConfigPo;
import com.hmy.contract.service.contract.IContractConfigService;
import com.hmy.contract.service.dto.contract.ContractConfigDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 合同信息表 服务实现类
 *
 * @author seven.qi
 * @since 2023-12-02
 */
@Service
@Slf4j
public class ContractConfigServiceImpl extends ServiceImpl<ContractConfigMapper, ContractConfigPo> implements IContractConfigService {
    @Resource
    private ContractConfigMapper contractConfigMapper;

    @Override
    public ContractConfigDto checkConfigExist(Integer businessType) {
        log.info("checkConfigExist businessType:{}", businessType);
        LambdaQueryWrapper<ContractConfigPo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ContractConfigPo::getContractBusinessType, businessType);
        wrapper.eq(ContractConfigPo::getIsDeleted, Boolean.FALSE);
        ContractConfigPo contractConfigRo = contractConfigMapper.selectOne(wrapper);
        if (Objects.isNull(contractConfigRo)) {
            log.info("contractConfig not exist businessType:{}", businessType);
            throw new HMYRuntimeException(502000017);
        }
        return BeanUtil.copyProperties(contractConfigRo, ContractConfigDto.class);
    }
}
